﻿using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace HalconDotNet
{
	// Token: 0x02000099 RID: 153
	internal class HTupleInt64 : HTupleImplementation
	{
		// Token: 0x06001F7D RID: 8061 RVA: 0x000B9CED File Offset: 0x000B7EED
		protected override Array CreateArray(int size)
		{
			return new long[size];
		}

		// Token: 0x06001F7E RID: 8062 RVA: 0x000B9CF5 File Offset: 0x000B7EF5
		protected override void NotifyArrayUpdate()
		{
			this.l = (long[])this.data;
		}

		// Token: 0x06001F7F RID: 8063 RVA: 0x000B9D08 File Offset: 0x000B7F08
		internal override void PinTuple()
		{
			Monitor.Enter(this);
			if (this.pinCount == 0)
			{
				this.pinHandle = GCHandle.Alloc(this.l, GCHandleType.Pinned);
			}
			this.pinCount++;
			Monitor.Exit(this);
		}

		// Token: 0x06001F80 RID: 8064 RVA: 0x000B9D3E File Offset: 0x000B7F3E
		public HTupleInt64(long l)
		{
			base.SetArray(new long[]
			{
				l
			}, false);
		}

		// Token: 0x06001F81 RID: 8065 RVA: 0x000B9AE4 File Offset: 0x000B7CE4
		public HTupleInt64(long[] l, bool copy)
		{
			base.SetArray(l, copy);
		}

		// Token: 0x06001F82 RID: 8066 RVA: 0x000B9D57 File Offset: 0x000B7F57
		public override HTupleElements GetElement(int index, HTuple parent)
		{
			return new HTupleElements(parent, this, index);
		}

		// Token: 0x06001F83 RID: 8067 RVA: 0x000B9D61 File Offset: 0x000B7F61
		public override HTupleElements GetElements(int[] indices, HTuple parent)
		{
			if (indices == null || indices.Length == 0)
			{
				return new HTupleElements();
			}
			return new HTupleElements(parent, this, indices);
		}

		// Token: 0x06001F84 RID: 8068 RVA: 0x000B9D78 File Offset: 0x000B7F78
		public override void SetElements(int[] indices, HTupleElements elements)
		{
			new HTupleElementsInt64(this, indices).setL(elements.LArr);
		}

		// Token: 0x17000096 RID: 150
		// (get) Token: 0x06001F85 RID: 8069 RVA: 0x000B9D8C File Offset: 0x000B7F8C
		// (set) Token: 0x06001F86 RID: 8070 RVA: 0x000B9B31 File Offset: 0x000B7D31
		public override long[] LArr
		{
			get
			{
				return this.l;
			}
			set
			{
				base.SetArray(value, false);
			}
		}

		// Token: 0x17000097 RID: 151
		// (get) Token: 0x06001F87 RID: 8071 RVA: 0x000B8665 File Offset: 0x000B6865
		public override HTupleType Type
		{
			get
			{
				return HTupleType.LONG;
			}
		}

		// Token: 0x06001F88 RID: 8072 RVA: 0x000B9D94 File Offset: 0x000B7F94
		public override int[] ToIArr()
		{
			int[] array = new int[this.iLength];
			for (int i = 0; i < this.iLength; i++)
			{
				array[i] = (int)this.l[i];
			}
			return array;
		}

		// Token: 0x06001F89 RID: 8073 RVA: 0x000B9B4E File Offset: 0x000B7D4E
		public override long[] ToLArr()
		{
			return (long[])base.ToArray(this.typeL);
		}

		// Token: 0x06001F8A RID: 8074 RVA: 0x000B9B61 File Offset: 0x000B7D61
		public override double[] ToDArr()
		{
			return (double[])base.ToArray(this.typeD);
		}

		// Token: 0x06001F8B RID: 8075 RVA: 0x000B9B74 File Offset: 0x000B7D74
		public override float[] ToFArr()
		{
			return (float[])base.ToArray(this.typeF);
		}

		// Token: 0x06001F8C RID: 8076 RVA: 0x000B9DCC File Offset: 0x000B7FCC
		public override IntPtr[] ToIPArr()
		{
			if (!HalconAPI.isPlatform64)
			{
				base.ToIPArr();
			}
			IntPtr[] array = new IntPtr[this.iLength];
			for (int i = 0; i < this.iLength; i++)
			{
				array[i] = new IntPtr(this.l[i]);
			}
			return array;
		}

		// Token: 0x06001F8D RID: 8077 RVA: 0x000B9E15 File Offset: 0x000B8015
		public override int CopyToLArr(long[] dst, int offset)
		{
			Array.Copy(this.l, 0, dst, offset, this.iLength);
			return this.iLength;
		}

		// Token: 0x06001F8E RID: 8078 RVA: 0x000B9E34 File Offset: 0x000B8034
		public override int CopyToOArr(object[] dst, int offset)
		{
			for (int i = 0; i < this.iLength; i++)
			{
				dst[i + offset] = this.l[i];
			}
			return this.iLength;
		}

		// Token: 0x06001F8F RID: 8079 RVA: 0x000B9E6A File Offset: 0x000B806A
		public override int CopyFrom(HTupleImplementation impl, int offset)
		{
			return impl.CopyToLArr(this.l, offset);
		}

		// Token: 0x06001F90 RID: 8080 RVA: 0x000B9E7C File Offset: 0x000B807C
		public override void Store(IntPtr proc, int parIndex)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.GetInputTuple(proc, parIndex, out tuple));
			this.StoreData(proc, tuple);
		}

		// Token: 0x06001F91 RID: 8081 RVA: 0x000B9EA0 File Offset: 0x000B80A0
		protected override void StoreData(IntPtr proc, IntPtr tuple)
		{
			this.PinTuple();
			if (!HalconAPI.isPlatform64)
			{
				HalconAPI.HCkP(proc, HalconAPI.CreateElementsOfType(tuple, base.Length, HTupleType.INTEGER));
				for (int i = 0; i < base.Length; i++)
				{
					HalconAPI.SetL(tuple, i, this.l[i]);
				}
				return;
			}
			HalconAPI.SetLArrPtr(tuple, this.l, this.iLength);
		}

		// Token: 0x06001F92 RID: 8082 RVA: 0x000B9F04 File Offset: 0x000B8104
		public static int Load(IntPtr tuple, out HTupleInt64 data)
		{
			int num;
			HalconAPI.GetTupleLength(tuple, out num);
			long[] longArray = new long[num];
			int larr = HalconAPI.GetLArr(tuple, longArray);
			data = new HTupleInt64(longArray, false);
			return larr;
		}

		// Token: 0x04001187 RID: 4487
		protected long[] l;
	}
}
